package net.sudot.chess.business.dao;

import net.sudot.chess.business.model.RoomCustomerRef;
import org.springframework.stereotype.Repository;

import javax.persistence.TypedQuery;

/**
 * 房间和玩家关联
 *
 * @author tangjialin on 2018-03-03.
 */
@Repository
public class RoomCustomerRefDao extends BaseDao<RoomCustomerRef> {

    /**
     * 获取房间玩家关联信息
     *
     * @param roomId     房间主键
     * @param customerId 客户主键
     * @return 返回房间玩家关联信息
     */
    public RoomCustomerRef findByRoomAndCustomer(Long roomId, Long customerId) {
        String ql = "SELECT ref FROM RoomCustomerRef ref WHERE ref.roomId = :roomId AND ref.customerId = :customerId";
        TypedQuery<RoomCustomerRef> query = entityManager.createQuery(ql, RoomCustomerRef.class);
        query.setParameter("roomId", roomId);
        query.setParameter("customerId", customerId);
        return uniqueResult(query);
    }
}
